#include <stdio.h>

int main()
{
	int a[20];
	int i;

	for (i = 0; i < 20; i++)
		a[i] = i * 2;

	for (i = 0; i < 20; i++)
		printf("a[%d] = %d\n", i, a[i]);	// 0,2,4,6,8...38

	return 0;
}

#if 0
   0x8048430:	push   %ebp			$esp = (void *) 0xbffff0e8	$ebp = (void *) 0x0
   0x8048431:	mov    %esp,%ebp		esp=0xbffff0e8 ebp=0xbffff0e8
   0x8048433:	and    $0xfffffff0,%esp		esp=0xbffff0e0 ebp=0xbffff0e8
   0x8048436:	sub    $0x70,%esp		esp=0xbffff070 ebp=0xbffff0e8
   0x8048439:	movl   $0x0,0x6c(%esp)		0xbffff0dc:	0x00000000
   0x8048441:	jmp    0x8048457
   0x8048443:	mov    0x6c(%esp),%eax		// eax=0.....19
   0x8048447:	lea    (%eax,%eax,1),%edx	// edx=0+0*1=0, 1+1*1=2,4,6,8....
   0x804844a:	mov    0x6c(%esp),%eax		// eax=0,1,2....
   0x804844e:	mov    %edx,0x1c(%esp,%eax,4)	// 0xbffff070+0*4+0x1c=0xbffff08c:0x00000000 0xbffff070+1*4+0x1c=0xbffff090:0x00000002,
                                                // 0xbffff070+2*4+0x1c=0xbffff094:0x00000004 0xbffff098:0x00000006 0xbffff09c:0x00000008 
						// 0xbffff0a0:0x0000000a
   0x8048452:	addl   $0x1,0x6c(%esp)		// i=0.....19
   0x8048457:	cmpl   $0x13,0x6c(%esp)	
   0x804845c:	jle    0x8048443

   0x804845e:	movl   $0x0,0x6c(%esp)
   0x8048466:	jmp    0x804848d
   0x8048468:	mov    0x6c(%esp),%eax		// eax=0,1...19
   0x804846c:	mov    0x1c(%esp,%eax,4),%eax	// 0xbffff08c:0x00000000 0xbffff090:0x00000002 0xbffff094:0x00000004
   0x8048470:	mov    %eax,0x8(%esp)		// 0xbffff078:0x00000000 0xbffff078:0x00000002
   0x8048474:	mov    0x6c(%esp),%eax		// eax=0,1...19
   0x8048478:	mov    %eax,0x4(%esp)		// 0xbffff074:0x00000000 0xbffff074:0x00000001
   0x804847c:	movl   $0x8048534,(%esp)	// 0xbffff070:0x08048534
   0x8048483:	call   0x80482f0 <printf@plt>	// printf(esp, esp+4, esp+8) ==> ("a[%d]", i, a[i])
   0x8048488:	addl   $0x1,0x6c(%esp)
   0x804848d:	cmpl   $0x13,0x6c(%esp)
   0x8048492:	jle    0x8048468
   0x8048494:	mov    $0x0,%eax
   0x8048499:	leave  
   0x804849a:	ret 

#endif

#if 0
/*
 * intel
 */
0000000000001169 <main>:
    1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp
    116e:	48 89 e5             	mov    %rsp,%rbp
    1171:	48 83 ec 70          	sub    $0x70,%rsp
    1175:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    117c:	00 00 
    117e:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    1182:	31 c0                	xor    %eax,%eax

    1184:	c7 45 9c 00 00 00 00 	movl   $0x0,-0x64(%rbp)		// i=0
    118b:	eb 13                	jmp    11a0 <main+0x37>		// for
    118d:	8b 45 9c             	mov    -0x64(%rbp),%eax		// eax=i
    1190:	8d 14 00             	lea    (%rax,%rax,1),%edx	// edx=(rax+rax*1)=i*2
    1193:	8b 45 9c             	mov    -0x64(%rbp),%eax		// eax=i
    1196:	48 98                	cltq   
    1198:	89 54 85 a0          	mov    %edx,-0x60(%rbp,%rax,4)	// (rbp+rax*4)-0x60
    119c:	83 45 9c 01          	addl   $0x1,-0x64(%rbp)		// i++
    11a0:	83 7d 9c 13          	cmpl   $0x13,-0x64(%rbp)	// for condition == i < 20
    11a4:	7e e7                	jle    118d <main+0x24>		// i <= 19

    11a6:	c7 45 9c 00 00 00 00 	movl   $0x0,-0x64(%rbp)		// i = 0
    11ad:	eb 23                	jmp    11d2 <main+0x69>		// for
    11af:	8b 45 9c             	mov    -0x64(%rbp),%eax		// eax=i
    11b2:	48 98                	cltq   
    11b4:	8b 54 85 a0          	mov    -0x60(%rbp,%rax,4),%edx
    11b8:	8b 45 9c             	mov    -0x64(%rbp),%eax
    11bb:	89 c6                	mov    %eax,%esi
    11bd:	48 8d 3d 40 0e 00 00 	lea    0xe40(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    11c4:	b8 00 00 00 00       	mov    $0x0,%eax
    11c9:	e8 a2 fe ff ff       	callq  1070 <printf@plt>
    11ce:	83 45 9c 01          	addl   $0x1,-0x64(%rbp)		// i++
    11d2:	83 7d 9c 13          	cmpl   $0x13,-0x64(%rbp)	// for condition == i < 20
    11d6:	7e d7                	jle    11af <main+0x46>		// i <= 19

    11d8:	b8 00 00 00 00       	mov    $0x0,%eax
    11dd:	48 8b 4d f8          	mov    -0x8(%rbp),%rcx
    11e1:	64 48 33 0c 25 28 00 	xor    %fs:0x28,%rcx
    11e8:	00 00 
    11ea:	74 05                	je     11f1 <main+0x88>
    11ec:	e8 6f fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    11f1:	c9                   	leaveq 
    11f2:	c3                   	retq   
    11f3:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    11fa:	00 00 00 
    11fd:	0f 1f 00             	nopl   (%rax)

/*
 * arm
 */
000000000040055c <main>:
  40055c:	a9b97bfd 	stp	x29, x30, [sp, #-112]!
  400560:	910003fd 	mov	x29, sp

  400564:	b9006fbf 	str	wzr, [x29, #108]	// i = 0
  400568:	1400000a 	b	400590 <main+0x34>
  40056c:	b9406fa0 	ldr	w0, [x29, #108]		// w0=i
  400570:	531f7802 	lsl	w2, w0, #1		// w2=i<<1 = i*2
  400574:	b9806fa0 	ldrsw	x0, [x29, #108]		// x0=i
  400578:	d37ef400 	lsl	x0, x0, #2		// x0=i<<2 ==> [0,4,8 ...] address offset.
  40057c:	910063a1 	add	x1, x29, #0x18		// x1=x29+0x18
  400580:	b8206822 	str	w2, [x1, x0]		// [x1+x0]=i*2	==> [x29+0x18+i*4]=i*2
  400584:	b9406fa0 	ldr	w0, [x29, #108]		// w0=i
  400588:	11000400 	add	w0, w0, #0x1		// i++
  40058c:	b9006fa0 	str	w0, [x29, #108]		// [x29+108]=w0
  400590:	b9406fa0 	ldr	w0, [x29, #108]		// w0=i
  400594:	71004c1f 	cmp	w0, #0x13
  400598:	54fffead 	b.le	40056c <main+0x10>

  40059c:	b9006fbf 	str	wzr, [x29, #108]
  4005a0:	1400000d 	b	4005d4 <main+0x78>
  4005a4:	b9806fa0 	ldrsw	x0, [x29, #108]
  4005a8:	d37ef400 	lsl	x0, x0, #2
  4005ac:	910063a1 	add	x1, x29, #0x18
  4005b0:	b8606821 	ldr	w1, [x1, x0]
  4005b4:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005b8:	911a8000 	add	x0, x0, #0x6a0
  4005bc:	2a0103e2 	mov	w2, w1
  4005c0:	b9406fa1 	ldr	w1, [x29, #108]
  4005c4:	97ffffa3 	bl	400450 <printf@plt>
  4005c8:	b9406fa0 	ldr	w0, [x29, #108]
  4005cc:	11000400 	add	w0, w0, #0x1
  4005d0:	b9006fa0 	str	w0, [x29, #108]
  4005d4:	b9406fa0 	ldr	w0, [x29, #108]
  4005d8:	71004c1f 	cmp	w0, #0x13
  4005dc:	54fffe4d 	b.le	4005a4 <main+0x48>

  4005e0:	52800000 	mov	w0, #0x0                   	// #0
  4005e4:	a8c77bfd 	ldp	x29, x30, [sp], #112
  4005e8:	d65f03c0 	ret
  4005ec:	00000000 	.inst	0x00000000 ; undefined


#endif

